package handler;

import com.sun.net.httpserver.HttpExchange;
import constant.Constants;
import model.CustomerSessions;
import util.ResponseUtil;
import java.io.IOException;
import java.util.Map;
import java.util.Random;
import java.util.concurrent.ConcurrentHashMap;
/**
 * @Description 获取或创建会话
 * @Author admin
 * @Date 2024-12-25 11:36
 */
public class SessionHandler {

    private final CustomerSessions customerSessions;

    public SessionHandler(CustomerSessions customerSessions) {
        this.customerSessions = customerSessions;
    }

    public void doHandler(String customerIdStr, HttpExchange exchange) throws IOException {
        int customerId = Integer.parseInt(customerIdStr);
        String sessionKey = customerSessions.getOrCreateSession(customerId).getSessionKey();
        ResponseUtil.sendResponse(exchange, sessionKey);
    }
}
